/*
 * Copyright (c) 2008 Ricardo Rocha, rocha.porto@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.gliding.kumulus.client;

import org.gliding.kumulus.client.model.PlanningContext;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;

/**
 * Class defining a Kumulus application Planning component.
 * 
 * @author Ricardo Rocha <rocha.porto@gmail.com>
 * @version $Rev:: $
 */
public class Planning extends Composite {

	/**
	 * Holds the planning menu widget and the period view widget.
	 */
    private HorizontalPanel planningPanel = new HorizontalPanel();
    
    /**
     * The planning menu widget.
     */
    private PlanningMenu menuWidget = new PlanningMenu();
    
    /**
     * The container for the view area of the selected period.
     */
    private RoundedPanel periodViewPanel = new RoundedPanel();
    
    /**
     * The Planning application context, holding all the model data. 
     */
    private PlanningContext planningContext = PlanningContext.getPlanningContext();
    
    /**
     * The widget containing the view of the selected period.
     */
    private PlanningView periodViewWidget = new PlanningView(planningContext);
    
	/**
	 * Class constructor.
	 * 
	 * Initializes the Planning widget, adding the menu widget and
	 * the period view container widget.
	 * 
	 */
	public Planning() {
        // Add the menu and the planning widgets
        planningPanel.add(menuWidget);
        // Could not find a way to do this via CSS
        planningPanel.setCellWidth(menuWidget, "175px");
        
        // Add the period view panel
        periodViewPanel.setStyleName("kumulus-PlanningPeriodView");
        periodViewPanel.setCornerStyleName("kumulus-WidgetCornerSelected");
        planningPanel.add(periodViewPanel);
        periodViewPanel.add(periodViewWidget);
        planningContext.addPlanningContextUpdateListener(periodViewWidget);
        
        // Initialize the widget and set the CSS style
        initWidget(planningPanel);
        setStyleName("kumulus-Planning");
	}

}
